<?php
/**
 * @category   Application_Extensions
 * @package    Talktangle Plugin 
 * @copyright  Idragon Co., Ltd.
 * @license
 */
class Talktangle_Widget_VidtangleController extends Engine_Content_Widget_Abstract {
		
	public function indexAction() {
	    
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $this->view->viewer = $viewer = Engine_Api::_()->user()->getViewer();
        $picApi = Engine_Api::_()->getApi('ptangle','talktangle');
        
        $id = $request->getParam('id');
        if(empty($id)) {
            return $this->setNoRender();
        } 
        $pic = Engine_Api::_()->getItem('talktangle_vidtangle',$id);
        if(!$pic){
            return $this->setNoRender();
        } 
        
        if ($pic->status != Talktangle_Api_Core::TANGLE_STATUS_NEW){
            $this->view->pic = $pic;
            $this->view->error = true;
            return ;
        }
        
        $offsets = $picApi->getAllOffsetOfTangle($pic);
        $matrixImag = array();
        foreach($offsets as $item){
            
            $matrixImag[] = $item->map();
        }
        
        $this->view->matrixImg = $matrixImag;
        $matrix = $picApi->initMatrix();
        $this->view->matrix = $matrix;
        $pic_session = new Zend_Session_Namespace('pic_session');
        $pic_session->matrix = $matrix;
        $this->view->pic_id = $id;
        $this->view->pic = $pic;
	}
}